package algutil.partagemusic.bo;

import java.io.File;

public class EntryFromToGetFile {

	private File f;
	private String lineFromToGetFile;

	public EntryFromToGetFile(ToGetFile toGetFile, String lineFromToGetFile) {
		this.lineFromToGetFile = lineFromToGetFile;
		this.f = new File(toGetFile.getFile().getParent()
				+ File.separator
				+ lineFromToGetFile
						.substring(0, lineFromToGetFile.indexOf(":")));
		this.sizeExpected = Long.parseLong(lineFromToGetFile
				.substring(lineFromToGetFile.indexOf(":") + 1));
	}

	private long sizeExpected;

	public File getFile() {
		return f;
	}

	public void setFile(File f) {
		this.f = f;
	}

	public String getRelativePath() {

		if (f == null) {
			return null;
		}

		return f.getPath().substring(f.getPath().indexOf("\\out\\") + 5);
	}

	public long getSizeExpected() {
		return sizeExpected;
	}

	public void setSizeExpected(long sizeExpected) {
		this.sizeExpected = sizeExpected;
	}

	public boolean isComplete() {
		if (exists()
				&& ((f.isFile() && f.length() == sizeExpected) || (f
						.isDirectory() && sizeExpected == -1))) {
			return true;
		}
		return false;
	}

	public boolean exists() {
		if (f.exists()) {
			return true;
		}
		return false;
	}

	public boolean isDirectory() {
		return f.isDirectory();
	}

	public File getParentFile() {
		return f.getParentFile();
	}

	public String toString() {
		return "[file='" + f.getPath() + "';size=" + sizeExpected + "] exists?"
				+ exists() + " complete?" + isComplete();
	}

	public boolean isFichierALaRacineDuRep2Partage() {
		if (getRelativePath().indexOf(File.separator, 1) == -1) {
			return true;
		} else {
			return false;
		}
	}

	public File getF() {
		return f;
	}

	public void setF(File f) {
		this.f = f;
	}

	public String getLineFromToGetFile() {
		return lineFromToGetFile;
	}

	public void setLineFromToGetFile(String lineFromToGetFile) {
		this.lineFromToGetFile = lineFromToGetFile;
	}
}
